package com.blog.controller;

import com.blog.Utils.Result;
import com.blog.annotion.LoginAnnotatio;
import com.blog.bean.dto.ExamineDTO;
import com.blog.bean.dto.UserExamineDTO;
import com.blog.bean.vo.ExamineVo;
import com.blog.service.ExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 任浩
 * @version 1.0
 */

@RestController
@RequestMapping("/examine")
public class ExamineController {

    @Autowired
    private ExamineService examineService;

    /**
     * 随机获得题目进行练习。
     * @return
     */
    @GetMapping("/list")
    @LoginAnnotatio
    public Result<ExamineVo> getExamineList() {
        ExamineVo examineVo = examineService.getExameneList();
        return Result.success(examineVo);
    }

    /**
     * 返回提交答案的结果,由前端返回一个数组类型的json字符串，我们进行解析。
     * @return
     */
    @PostMapping("/submit")
    @LoginAnnotatio
    public Result<ExamineVo> sumbitExamine(@RequestBody UserExamineDTO answer) {
        ExamineVo examineVo = examineService.submitExamine(answer);
        return Result.success(examineVo);
    }
}
